package com.wish.building.controller;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.building.entity.SProvinces;
import com.wish.building.entity.TbMapHouse;
import com.wish.building.service.ISProvincesService;
import com.wish.building.service.ITbMapHouseService;
import com.wish.common.core.usconfig.common.MsgResult;
import com.wish.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 地图找房测试表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-04-06
 */
@RestController
@RequestMapping("/tb-map-house")
public class TbMapHouseController {

	@Autowired
	ISProvincesService isProvincesService;

	@Autowired
	ITbMapHouseService iTbMapHouseService;

	@Autowired
	RedisService redisService;

	@GetMapping("findAllCity")
	public MsgResult findAllCity(){
			List<SProvinces> list = isProvincesService.list();
			List<Tree<Integer>> build = TreeUtil.build(list, 100000,
					(provinces, tree) -> {
						tree.setParentId(provinces.getParentId());
						tree.setId(provinces.getId());
						tree.setName(provinces.getCityName());
						tree.putExtra("value",provinces.getId());
						tree.putExtra("label",provinces.getCityName());
					});
		return MsgResult.succeed(build);
	}

	@GetMapping("findCityById")
	public MsgResult findCityById(SProvinces sProvinces){
		List<SProvinces> list = isProvincesService.listById(sProvinces);
		return MsgResult.succeed(list);
	}

	@GetMapping("findHouse")
	public MsgResult findHouse(SProvinces sProvinces){
		List<TbMapHouse> list = iTbMapHouseService.listByCounty(sProvinces);
		return MsgResult.succeed(list);
	}


}
